Adding hook to enable index matching through type casts#762
Open
RuchaSK1 wants to merge 2 commits into
Open
Conversation
Signed-off-by: Rucha Kulkarni <ruchask@amazon.com>
Signed-off-by: Rucha Kulkarni <ruchask@amazon.com>
rohit01010
approved these changes
Jun 16, 2026
KushaalShroff
requested changes
Jun 16, 2026
| */ | ||
| set_opfuncid(clause); /* make sure we have opfuncid */ | ||
| return get_index_clause_from_support(root, | ||
| iclause = get_index_clause_from_support(root, |
Contributor
There was a problem hiding this comment.
Can you repro the index scan not being chosen in PG?
Contributor
Author
There was a problem hiding this comment.
dev-dsk-ruchask-1c-a99d43f3 % psql -h localhost -d postgres
psql (18.3)
Type "help" for help.
postgres=# CREATE TABLE test_oid (id oid PRIMARY KEY, data text);
CREATE TABLE
postgres=# INSERT INTO test_oid SELECT g, 'row ' || g FROM generate_series(1, 100000) g;
INSERT 0 100000
postgres=# EXPLAIN SELECT * FROM test_oid WHERE id = 12345;
QUERY PLAN
-------------------------------------------------------------------------------
Index Scan using test_oid_pkey on test_oid (cost=0.29..8.31 rows=1 width=36)
Index Cond: (id = '12345'::oid)
(2 rows)
postgres=# EXPLAIN SELECT * FROM test_oid WHERE (id)::int = 12345;
QUERY PLAN
------------------------------------------------------------
Seq Scan on test_oid (cost=0.00..1399.84 rows=1 width=36)
Filter: ((id)::integer = 12345)
(2 rows)
postgres=# EXPLAIN SELECT * FROM test_oid WHERE (id)::int4 = 12345;
QUERY PLAN
------------------------------------------------------------
Seq Scan on test_oid (cost=0.00..1791.00 rows=1 width=13)
Filter: ((id)::integer = 12345)
(2 rows)
postgres=#
Contributor
Author
There was a problem hiding this comment.
With catalog table:
postgres=# EXPLAIN SELECT * FROM pg_class WHERE oid = 12345;
QUERY PLAN
-------------------------------------------------------------------------------------
Index Scan using pg_class_oid_index on pg_class (cost=0.27..8.29 rows=1 width=277)
Index Cond: (oid = '12345'::oid)
(2 rows)
postgres=# EXPLAIN SELECT * FROM pg_class WHERE (oid)::int4 = 12345;
QUERY PLAN
-----------------------------------------------------------
Seq Scan on pg_class (cost=0.00..19.19 rows=1 width=277)
Filter: ((oid)::integer = 12345)
(2 rows)
Contributor
Author
|
/code-review |
1 similar comment
Contributor
Author
|
/code-review |
1 task
KushaalShroff
approved these changes
Jun 17, 2026
Contributor
Author
|
/code-review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adding a hook in match_opclause_to_indexcol() that allows babelfish to provide index clauses when the built-in logic cannot match an OpExpr to an index column. This enables extensions to handle type-cast patterns that prevent index usage due to operator family mismatches.
Issues Resolved
Task: BABEL-6814
Authored-by: Rucha Kulkarni ruchask@amazon.com
Signed-off-by: Rucha Kulkarni ruchask@amazon.com
Extension PR: babelfish-for-postgresql/babelfish_extensions#4829
Check List
By submitting this pull request, I confirm that my contribution is under the terms of the PostgreSQL license, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.